StackPlot p;

void setup(){
  background(0);
  size(700, 400);
  
  int[][] freqArray = fillFreqArray();
  int[][] freqArray2 = fillFreqArray();
  
  int[] quakeMagColors = new int[7];
  quakeMagColors[0] = 0xFFFEE5D9;
  quakeMagColors[1] = 0xFFFCBBA1;
  quakeMagColors[2] = 0xFFFC9272;
  quakeMagColors[3] = 0xFFFB6A4A;
  quakeMagColors[4] = 0xFFEF3B2C;
  quakeMagColors[5] = 0xFFCB181D;
  quakeMagColors[6] = 0xFF99000D;
  
  //int[][] freqArray, Date dateMin, Date dateMax, float plotX1, float plotY1, float plotX2, float plotY2, String title,
             //String xAxisTitle, String yAxisTitle, int[] categoryColors ) {
  p = new StackPlot( freqArray, new Date(1, 1972), new Date( 12, 2010 ), 150, 50, width-50, height-50, "Quake frequency by magnitude", "Year", 
    "frequency\nof quakes\n per month\nby magnitude", quakeMagColors);
}

void draw(){
  background(0);
  p.drawPlot();
}

int[][] fillFreqArray(){
  int[][] freqArray;
  int numYears = 2010-1972 + 1;
  freqArray = new int[7][numYears*12];
  for(int category = 0; category < freqArray.length; category++){
    for(int theMonth = 0; theMonth < freqArray[category].length; theMonth++){
      if( category == 0 ){
        freqArray[category][theMonth] = (int) random(30, 50);
      } else if( category == 1 ) { //mag 0-4
        freqArray[category][theMonth] = (int) random(170, 300);
      } else if( category == 2 ){//mag 4-5
        freqArray[category][theMonth] = (int) random(70, 170); 
      } else if( category == 3 ){//mag 5-6
        freqArray[category][theMonth] = (int) random(5, 10);
      } else if( category == 4 ){//mag 6-7
        freqArray[category][theMonth] = (int) random(0, 10); 
      } else if(category == 5 ){
        freqArray[category][theMonth] = (int) random(0, 3);
      } else if( category == 6 ){
        freqArray[category][theMonth] = (int) random(0, 2);
      } 
    }//end inner for loop
  }//end outer for loop
  
  return freqArray;
}

//change of dates
int[][] fillFreqArray2(){
  int[][] freqArray2;
  int numYears = 2010-1980 + 1;
  freqArray2 = new int[7][numYears*12];
  for(int category = 0; category < freqArray2.length; category++){
    for(int theMonth = 0; theMonth < freqArray2[category].length; theMonth++){
      if( category == 0 ){
        freqArray2[category][theMonth] = (int) random(30, 50);
      } else if( category == 1 ) { //mag 0-4
        freqArray2[category][theMonth] = (int) random(170, 300);
      } else if( category == 2 ){//mag 4-5
        freqArray2[category][theMonth] = (int) random(70, 170); 
      } else if( category == 3 ){//mag 5-6
        freqArray2[category][theMonth] = (int) random(5, 10);
      } else if( category == 4 ){//mag 6-7
        freqArray2[category][theMonth] = (int) random(0, 10); 
      } else if(category == 5 ){
        freqArray2[category][theMonth] = (int) random(0, 3);
      } else if( category == 6 ){
        freqArray2[category][theMonth] = (int) random(0, 2);
      } 
    }//end inner for loop
  }//end outer for loop
  
  return freqArray2;
}

void keyPressed(){
  if( key == 'd' ){
    p.changeDateRange( new Date( 2, 1980 ), new Date( 5, 2007 ) );
  }
  if( key == '0' ){
    p.removeCategory(0);
  }
  if( key == '1' ){
    p.removeCategory(1);
  }
  if( key == '2'){
    p.removeCategory(2);
  }
  if( key == '3' ){
    p.removeCategory(3);
  }
  if( key == 'z' ){
    p.addCategory(0);
  }
  if( key == 'o' ){
    p.addCategory(1);
  }
  if( key == 't' ){
    p.addCategory(2);
  }
  if( key == 'h' ){
    p.addCategory(3);
  }
}
